import java.util.*;

public class Main2 {

    public static int n;
    public static int[] minArr;
    public static int[] arr;
    public static int count;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t > 0) {
            t--;
            n = sc.nextInt();
            minArr = new int[n];
            count = 0;

            arr = new int[n];
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                set.add(arr[i]);
            }
            int size = set.size();

            if (n == 2) {
                if (arr[0] > arr[1] || arr[0] < arr[1]) {
                    System.out.println(0);
                } else if (arr[0] == 1 && arr[1] == arr[0]) {
                    System.out.println(1);
                } else if (arr[0] == 2 && arr[1] == arr[0]) {
                    System.out.println(0);
                }
            } else {
                long ret = 1;
                int count = n - size;
                while (count > 0) {
                    ret = (ret * count) % 998244353;
                    count--;
                }
                System.out.println(ret);
            }
        }

        sc.close();
    }

    public static void dfs(int index, int preMin, Map<Integer, Boolean> map) {
        if (index == n) {
            count++;
            return;
        }

        if (minArr[index] < preMin) {
            arr[index] = minArr[index];
            map.put(index, true);
            dfs(index + 1, minArr[index], map);
        } else {
            for (int i = preMin + 1; i <= n; i++) {
                if (!map.get(i)) {
                    arr[index] = i;
                    map.put(i, true);
                    dfs(index + 1, minArr[index], map);

                    //回溯
                    arr[index] = 0;
                    map.put(i, false);
                }
            }
        }
    }
}
